package com.magiccompass.alipay.barcode.entity;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;

import com.magiccompass.alipay.barcode.constants.BusinessLogicConstants;

@Entity
@Table(name = "TD_MERCHANT_INFO")
@DynamicUpdate(value= true)
public class MerchantInfo {
	@Id
	@Column(name = "ID")
	@GeneratedValue
	private Integer id;
	
	@Column(name = "merchant_name", length=512, nullable=false)
    private String merchantName;
	
	@Column(name = "email", length=512, nullable=false)
    private String email = "";
	
	@Column(name = "default_currency", length=8, nullable=false)
    private String defaultCurrency=BusinessLogicConstants.CURRENCY;
    
	@Column(name = "create_by", nullable=false)
	private Integer createBy=BusinessLogicConstants.SYSTEM_CREATOR_ID;
	
	@Column(name = "create_time", nullable=false)
	private Timestamp createTime = new Timestamp(Calendar.getInstance().getTimeInMillis());

	@Column(name = "update_by")
	private Integer updateby;

	@Column(name = "update_time")
	private Timestamp updateTime;
	
	@Column(name = "del_flag")
	private String delFlag = "F";
	
	@Column(name = "display_name", length=256, nullable=false)
    private String displayName;
	
	@Column(name = "fee_rate", nullable=false,precision=4, scale=2)
    private BigDecimal feeRate = new BigDecimal(2.5);
	
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "merchant", orphanRemoval = true)
	private List<MerchantBankAccount> merchantBankAccounts = new ArrayList<MerchantBankAccount>();
	
	@Column(name = "industry", length=4, nullable=false)
    private String industry="5311";
	
	@OneToMany(cascade=CascadeType.ALL,fetch = FetchType.LAZY, mappedBy = "merchant", orphanRemoval = true)
	private List<MerchantEmails> merchantEmails = new ArrayList<MerchantEmails>();
	
	@ManyToOne( cascade=CascadeType.REFRESH, fetch=FetchType.LAZY )
	@JoinColumn(name="merchant_group_id")
    private MerchantGroup merchantGroup;
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public Integer getCreateBy() {
		return createBy;
	}
	public void setCreateBy(Integer createBy) {
		this.createBy = createBy;
	}
	public Timestamp getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Timestamp createTime) {
		this.createTime = createTime;
	}
	public Integer getUpdateby() {
		return updateby;
	}
	public void setUpdateby(Integer updateby) {
		this.updateby = updateby;
	}
	public String getDelFlag() {
		return delFlag;
	}
	public void setDelFlag(String delFlag) {
		this.delFlag = delFlag;
	}
	public String getMerchantName() {
		return merchantName;
	}
	public void setMerchantName(String merchantName) {
		this.merchantName = merchantName;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getDefaultCurrency() {
		return defaultCurrency;
	}
	public void setDefaultCurrency(String defaultCurrency) {
		this.defaultCurrency = defaultCurrency;
	}
	public Timestamp getUpdateTime() {
		return updateTime;
	}
	public void setUpdateTime(Timestamp updateTime) {
		this.updateTime = updateTime;
	}
	public String getDisplayName() {
		return displayName;
	}
	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}
	public List<MerchantBankAccount> getMerchantBankAccounts() {
		return merchantBankAccounts;
	}
	public void setMerchantBankAccounts(List<MerchantBankAccount> merchantBankAccounts) {
		this.merchantBankAccounts = merchantBankAccounts;
	}
	public void addMerchantBankAccount(MerchantBankAccount ma){
		ma.setMerchant(this);
		this.merchantBankAccounts.add(ma);
	}
	public void removeAllMerchantBankAccount(){
		this.merchantBankAccounts = new ArrayList<MerchantBankAccount>();
	}
	public BigDecimal getFeeRate() {
		return feeRate;
	}
	public void setFeeRate(BigDecimal feeRate) {
		this.feeRate = feeRate;
	}
	public String getIndustry() {
		return industry;
	}
	public void setIndustry(String industry) {
		this.industry = industry;
	}
	public List<MerchantEmails> getMerchantEmails() {
		return merchantEmails;
	}
	public void setMerchantEmails(List<MerchantEmails> merchantEmails) {
		this.merchantEmails = merchantEmails;
	}
	public void addMerchantEmails(MerchantEmails me){
		me.setMerchant(this);
		this.merchantEmails.add(me);
	}
	public MerchantGroup getMerchantGroup() {
		return merchantGroup;
	}
	public void setMerchantGroup(MerchantGroup merchantGroup) {
		this.merchantGroup = merchantGroup;
	}
	
}